﻿package net.jmp0.toast.entities.obstacles 
{
	import flash.filters.BlurFilter;
	import flash.filters.DropShadowFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import net.jmp0.toast.entities.bases.GameElement;
	import punk.core.Spritemap;
	
	/**
	 * ...
	 * @author Thodd
	 */
	public class Teleporter extends Obstacle
	{
		[Embed(source = '../../res/teleporter.png')] private var imgTeleporter:Class;

		private var clr:uint; //The color of the Teleporter
		private var telepartner:Teleporter = this as Teleporter; //The teleportation partner
		
		public function Teleporter(x:int, y:int, clr:uint) {
			super(x, y);
			
			this.clr = clr;
			
			//setting up the sprite and coloring it
			sprite = FP.getSprite(imgTeleporter, 22, 22, false, false, 2, 2, false);
			var c:ColorTransform = new ColorTransform(1,1,1,1,0,0,0,0);
			c.color = this.clr;
			sprite.colorTransform(new Rectangle(0, 0, sprite.width, sprite.height), c);
			//sprite.applyFilter(sprite, new Rectangle(0, 0, sprite.width, sprite.height), new Point(0, 0), new DropShadowFilter(1,0,0x000000,1,1,1,1,1));
			
			this.randomizeAnimation();
			
		}
		
		public function getColor():uint {
			return clr;
		}
		
		public function getTelepartner():Teleporter {
			return telepartner;
		}
		
		public function setTelepartner(telepartner:Teleporter):void {
			this.telepartner = telepartner;
		}
		
		override public function performCollision(colPartner:GameElement):void {
			trace("Teleporter collision");
			colPartner.x = this.getTelepartner().x;
			colPartner.y = this.getTelepartner().y;
			colPartner.xSpeed = colPartner.oldXspeed;
			colPartner.ySpeed = colPartner.oldYspeed
			this.getTelepartner().getWobblingBehavior().wobble(colPartner);
			colPartner.lastCollision = this.getTelepartner();
		}
		
		//IMPORTANT!
		override public function destroy():void {
			//if a teleporter is destroyed (e.g. by an orange)
			//the telepartner of said teleporter is now pointing to itself
			//since teleporting to an now "unknown" teleporter doesn't make sense
			//when touching the remaining teleporter the player gets the illusion
			//he isn't teleporting at all but in reality he has teleported to the same
			//spot he started from... did that make any sense to you? :D
			this.telepartner.telepartner = this.telepartner;
			super.destroy();
		}
		
	}

}